package view;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.ActionListener;

import net.miginfocom.swing.MigLayout;

/**
 * Represents the login box that allows user to enter login 
 * information.
 * 
 * @author Kenny Chong, Dan End, James Ju 
 * CSE 333 : User Interface 
 * Project HMSystem
 */
public class LoginBox extends JPanel
{
	// Variables.
	private static LoginBox box;
	
	private final String title = "Welcome! Please Login!";
		
	private JLabel userNameLabel;
	private JLabel userPassLabel;
		
	private JTextField userNameField;
	private JPasswordField userPassField; 

	private JButton submitButton;
	private JButton helpButton;
	private JPanel buttonPanel;
	
	// Custom Layout.
	private MigLayout migLayout;
	
	/**
	 * Constructs the login box, using Singleton
	 * Pattern.
	 * @param panel
	 */
	private LoginBox()
	{}
	
	public static LoginBox getLoginBox()
	{
		if (box == null)
		{
			box = new LoginBox();
			box.init();
		} 
		return box;
	}
	
	/**
	 * Initialize the panel.
	 */
	public void init()
	{
		// Set border.
		Border etched = BorderFactory.createEtchedBorder();
		Border panelBorder = BorderFactory.createTitledBorder(etched, title);
		this.setBorder(panelBorder);
		
		// Set layout.
		migLayout = new MigLayout("", "[right]");
		this.setLayout(migLayout);
				
		// Initialize labels.
		userNameLabel = new JLabel("User Name:");
		userPassLabel = new JLabel("Password:");
		
		// Initialize fields.
		userNameField = new JTextField(15);
		userPassField = new JPasswordField(15);
		
		// Set fields with empty values.
		userNameField.setText("");
		userPassField.setText("");
		
		// Initialize buttons.
		submitButton = new JButton("Submit");
		helpButton = new JButton("Help");
		buttonPanel = new JPanel();
		
		// Add components.
		this.add(userNameLabel, "gap 10");
		this.add(userNameField, "span, growx");
				
		this.add(userPassLabel, "gap 10");
		this.add(userPassField, "span, growx, wrap");
				
		buttonPanel.add(submitButton);
		buttonPanel.add(helpButton);
				
		this.add(buttonPanel, "span, center");
	}
	
	// Getters.
	public JButton getSubmitButton()
	{
		return submitButton;
	}
	
	public JPasswordField getPasswordField()
	{
		return userPassField;
	}
	
	public JTextField getNameField()
	{
		return userNameField;
	}
	
	public JButton getHelpButton()
	{
		return helpButton;
	}
}
